<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of user
 *
 * @author agasi
 */
class Group_ajax extends CI_Controller {
    
    function __construct() 
    {
        parent::__construct();
        $this->load->model('sistem/group_model');
        $this->load->library('flexigrid');
//        $this->output->enable_profiler(TRUE);
    }
    
    function index()
    {
        $valid_fields = array('grp_id','grp_nama','grp_deskripsi');
		
        $this->flexigrid->validate_post('grp_id','asc',$valid_fields);

        $records = $this->group_model->get_all_group();

        $this->output->set_header($this->config->item('json_header'));

        /*
            * Json build WITH json_encode. If you do not have this function please read
            * http://flexigrid.eyeviewdesign.com/index.php/flexigrid/example#s3 to know how to use the alternative
            */
        $record_items = array();
        foreach ($records['records']->result() as $row)
        {
                $record_items[] = array($row->grp_id,
                $row->grp_id,
                $row->grp_nama,
                $row->grp_deskripsi,
                '<a href=\''.site_url('sistem/group_ajax/delete/'.$row->grp_id).'\'><img border=\'0\' src=\''.$this->config->item('base_url').'asset/images/icn_edit.png\'></a> '
                );
        }
        //Print please
        $this->output->set_output($this->flexigrid->json_build($records['record_count'],$record_items));
    }

    function delete_all()
    {
        
        $group_ids_post_array = mb_split(",",$this->input->post('items'));

        foreach($group_ids_post_array as $index => $group_id)
            if (is_numeric($group_id) && $group_id > 1) 
                    $this->group_model->delete_group($group_id);

        	
        $error = "Selected sys_group (id's: ".$this->input->post('items').") deleted with success.";

        $this->output->set_header($this->config->item('ajax_header'));
        $this->output->set_output($error);
    }
    
    function delete($group_id)
    {
        $this->group_model->delete_group($group_id);	
        $error = "Selected sys_group (id's: ".$this->input->post('items').") deleted with success.";

        $this->output->set_header($this->config->item('ajax_header'));
        $this->output->set_output($error);
    }
}

/* End of file user_ajax.php */
/* Location: ./application/controllers/sistem/user_ajax.php */